import interfaces.Port;
import exceptions.ExAddressInput;
import exceptions.ExPortConnection;
import protocols.*;

import java.util.concurrent.locks.ReentrantLock;



public class sistem implements Runnable{
	public sistem() {
		run();
	}
	public void run() {
		EthernetII arpf = null;
		EthernetII arpfrep = null;
		try {
			arpf = ARP.request(new EthernetII.MACaddress("ff:45:fb:01:45:cb"),new IPv4.IPv4address("255.2.5.23"),new IPv4.IPv4address("45.23.255.255"));
		} catch (ExAddressInput e) {e.printStackTrace();}
		System.out.println(arpf);
		try {
			arpfrep = ARP.reply(arpf, new EthernetII.MACaddress("2b:78:bc:60:fb:aa"));
		} catch (ExAddressInput e) {e.printStackTrace();}
		System.out.println(arpfrep);
		try {
			EthernetII.MACaddress a = new EthernetII.MACaddress("aa:45:fb:01:45:cb");
		} catch (ExAddressInput e) {e.printStackTrace();}
		
		Port port1 = null;
		try {
			port1 = new Port("ff:45:fb:01:45:cb");
		} catch (ExAddressInput e) {e.printStackTrace();}
		
		Port port2 = null;
		try {
			port2 = new Port("aa:45:fb:01:45:cb");
		} catch (ExAddressInput e) {e.printStackTrace();}
			
		Port port3 = null;
		try {
			port3 = new Port("ff:45:fb:01:45:cb");
		} catch (ExAddressInput e) {e.printStackTrace();}
		
		Port port4 = null;
		try {
			port4 = new Port("ff:45:fb:01:45:cb");
		} catch (ExAddressInput e) {e.printStackTrace();}

		
		try {
			port1.connect(port2);
		} catch (ExPortConnection e) {e.printStackTrace();}
		try {
			port3.connect(port4);
		} catch (ExPortConnection e) {e.printStackTrace();}



		port1.send(arpf);
		//System.out.println(port1.getSnd_buffer());
		//System.out.println(port2.getRcv_buffer());		

		//System.out.println(port1.getConnected_port().getRcv_buffer());
		


		port2.send(arpf);
		/*try {
			port1.disconnect();
		} catch (ExPortConnection e) {e.printStackTrace();}*/
		//for (int i = 0; i< 1000; i++) {int a1 = 12;}
		
		//System.out.println(port1.getRcv_buffer());

		//System.out.println(port2.connected_port.rcv_thread.getState());
		//System.out.println(this.)
	}
	public static void main(String[] args)  {
		new sistem();
	}
}

